package 
{
	import away3d.entities.Mesh;
	import away3d.materials.ColorMaterial;
	import away3d.materials.methods.PlanarReflectionMethod;
	import away3d.primitives.PlaneGeometry;
	import away3d.textures.PlanarReflectionTexture;
	
	import com.engine.AwayEngine;
	import com.manager.CarSence;
	import com.manager.Vision;
	import com.model.CarDataRemote;
	import com.ui.DetailFace;
	import com.ui.LoadingUI;
	import com.ui.MenuFace;
	import com.ui.ModelSelect;
	import com.ui.PartFace;
	import com.ui.TypeFace;
	
	import feathers.controls.text.TextFieldTextRenderer;
	
	import starling.display.Sprite;
	import starling.events.Event;
	
	import themes.AeonDesktopTheme.AeonDesktopTheme;
	import themes.MetalWorksMobileTheme.MetalWorksMobileTheme;

//	import themes.MinimalMobileTheme.MinimalMobileTheme;
	
	public class GameMain extends Sprite
	{
		public function GameMain()
		{
			new MetalWorksMobileTheme();
//			new AeonDesktopTheme();
//			new MinimalMobileTheme();
			
			TextFieldTextRenderer.defaultSize = 20;
			
			this.addEventListener(Event.ADDED_TO_STAGE,addToStage);
		}
		
		private function addToStage(e:Event):void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE,addToStage);
			Vision.createGpu(this);
			Vision.shield();
			
			init();
//			initMirror();
		}
		
		public function init():void{
			LoadingUI.getInstance().show();
//			MenuUI.getInstance().show(this);
			TypeFace.getInstance().show();
			ModelSelect.getInstance().show();
			DetailFace.getInstance().show();
			MenuFace.getInstance().show();
			PartFace.getInstance().show();
//			MenuUI.getInstance().vision = false;
		}
		/**
		 * 地面反射车模效果
		 */		
		private function initMirror() : void
		{
			var reflectionTexture:PlanarReflectionTexture = new PlanarReflectionTexture();
			var reflectionMethod:PlanarReflectionMethod = new PlanarReflectionMethod(reflectionTexture);
//			var reflectiveMaterial:ColorMaterial = new ColorMaterial(0xffff00,.2);
			var reflectiveMaterial:ColorMaterial = new ColorMaterial(0,.2);
			reflectiveMaterial.addMethod(reflectionMethod);
			AwayEngine.addReflect(reflectionTexture);
			var geometry:PlaneGeometry = new PlaneGeometry(1000, 1000, 1, 1, false);
			var mesh:Mesh = new Mesh(geometry, reflectiveMaterial);
			mesh.y = -5;
			mesh.rotationX= -270;
			mesh.rotationY = -100;
			mesh.rotationY = 180;
			AwayEngine.addMesh(mesh);
			reflectionTexture.applyTransform(mesh.sceneTransform);
			// need to apply plane's transform to the reflection, compatible with PlaneGeometry created in this manner
			// other ways is to set reflectionTexture.plane = new Plane3D(...)
		}
		
	}
}